package com.wzgl.core.model;


import java.util.LinkedList;
import java.util.List;

import com.jfinal.plugin.activerecord.Page;
import com.wzgl.core.base.Table;
import com.wzgl.core.baseModel.BaseDicSort;
import com.wzgl.core.utils.StringUtils;

/***
 * 数据字典表
 * @author Administrator
 *
 */
@Table(tableName = "tdicsort", primaryKey = "fid")
public class Tdicsort extends BaseDicSort<Tdicsort> {
	private static final long serialVersionUID = -1L;
	public static final Tdicsort dao = new Tdicsort();
	
	public List<Tdicsort> getAll(){
		return dao.find("select * from Tdicsort where fstats >=0");
	}
	
	public Tdicsort findById(final String fid) {
		return dao.doFindFirst("fid = ? and fstats >=0", fid);
	}
	
	public Tdicsort findByFname(final String fname) {
		return dao.doFindFirst("fname = ? and fstats >=0", fname);
	}
	
	public Tdicsort findBySort(final String fsortcode) {
		return dao.doFindFirst("fsortcode = ? and fstats >=0", fsortcode);
	}
	
	public Page<Tdicsort> getListByVal(int page, int pagesize,final String fname,final String fsortcode){
		LinkedList<Object> params = new LinkedList<Object>();
		StringBuilder sql = new StringBuilder(" from tdicsort u where 1 = 1 and fstats >=0");
		if (StringUtils.isNotBlank(fsortcode)) {
			sql.append(" AND u.fsortcode =  ? ");
			params.add(fsortcode);
		}
		if (StringUtils.isNotBlank(fname)) {
			sql.append(" AND u.fvalue like ? ");
			params.add("%" + fname + "%");
		}
		sql.append(" ORDER BY fid");
		return dao.paginate(page, pagesize, "select * ", sql.toString(), params.toArray());
	}
}
